home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / programer2 / euclidlib / c / esprite < prev    next >
Text File  |  1992-04-21  |  3KB  |  98 lines

  1. /**** esprite.c ****/
  2. /* By Paul Field
  3.  * See !ReadMe file for distribution/modification restrictions
  4.  */
  5.  
  6. #include "esprite.h"
  7.  
  8. #include <assert.h>
  9. #include <stdlib.h>
  10. #include "wimp.h"
  11. #include "bbc.h"
  12.  
  13. static os_error nomem = {0, "Not enough memory - increase Wimpslot."};
  14.  
  15. #if FALSE
  16. static void esprite_setcolour(int logical, wimp_paletteword col)
  17.  { bbc_palette(logical, 16, col.bytes.red, col.bytes.green, col.bytes.blue);
  18. #if FALSE
  19.    char block[5];
  20.    
  21.    block[0] = logical;
  22.    block[1] = 16;       /* Define colour by r,g,b */
  23.    block[2] = col.bytes.red;
  24.    block[3] = col.bytes.green;
  25.    block[4] = col.bytes.blue;
  26.    os_word(12,block);
  27. #endif
  28.  }
  29.  
  30.  
  31. static void esprite_setwimppalette(void)
  32.  { int maxcol;
  33.  
  34.    maxcol = bbc_vduvar(bbc_NColour);
  35.    if (maxcol < 64)
  36.     { wimp_palettestr palette;
  37.  
  38.       wimp_readpalette(&palette);
  39.       switch(maxcol)
  40.        { case 1:
  41.            esprite_setcolour(0, palette.c[0]);
  42.            esprite_setcolour(1, palette.c[7]);
  43.            break;
  44.          case 3:
  45.            esprite_setcolour(0, palette.c[0]);
  46.            esprite_setcolour(1, palette.c[2]);
  47.            esprite_setcolour(2, palette.c[4]);
  48.            esprite_setcolour(3, palette.c[7]);
  49.            break;
  50.          case 15:
  51.            for (; maxcol >= 0; maxcol--)
  52.             { esprite_setcolour(maxcol, palette.c[maxcol]);
  53.             }
  54.            break;
  55.        }
  56.     }
  57.  }
  58. #endif
  59.  
  60. os_error *esprite_draw(sprite_area **area, int offset, edraw_info *info)
  61.  { int savesize;
  62.    int *savearea;
  63.    sprite_id id;
  64.    os_error *e,*e2;
  65.  
  66.    id.tag = sprite_id_addr;
  67.    id.s.addr = (char *)*area + offset;
  68.  
  69.    if ((e = sprite_sizeof_spritecontext(*area, &id, &savesize)) == NULL)
  70.     { if ((savearea = malloc(savesize)) == NULL)
  71.        { return(&nomem);
  72.        }
  73.       else
  74.        { sprite_state state;
  75.  
  76.          savearea[0] = 0;
  77.          id.s.addr = (char *)*area + offset; /* The malloc may have moved a flex block */
  78.          if ((e = sprite_outputtosprite(*area, &id, savearea, &state)) == NULL)
  79.           { euclid_invalidatepalettecache(); /* Don't know if this is needed */
  80.                                              /* but best to be on the safe side */
  81.             if (info->structure->cache)
  82.              { *((unsigned int *)info->structure->cache + 1) = 0;
  83.              }
  84.             e = edraw_split(info);
  85.             e2 = sprite_restorestate(state);
  86.             if (!e)
  87.              { e = e2;
  88.              }
  89.             euclid_invalidatepalettecache(); /* Don't know if this is needed */
  90.                                              /* but best to be on the safe side */
  91.           }
  92.          free(savearea);
  93.        }
  94.     }
  95.    return(e);
  96.  }
  97.  
  98.